package com.projectpractice.controller;

import com.projectpractice.bean.User;
import com.projectpractice.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/*
 * @RestController=@Controller+@ResponseBody
 * @Controller 用于表示控制器类
 * @ResponseBody 返回的对象结果会被转为Json格式数据
 * */
@RestController
@RequestMapping("/index")
public class indexController {

    @Autowired
    UserService userService;

    @RequestMapping("/{name}")
    public ModelAndView toIndex(@PathVariable String name){
        System.out.println(name);

        ModelAndView mv=new ModelAndView();
        //设置视图
        mv.setViewName("index");
        User user=userService.getUserByName(name);
        //设置数据
        mv.addObject("user",user);
        return mv;
    }

    @RequestMapping("/welcome")
    public ModelAndView toWelcome(){
        ModelAndView mv=new ModelAndView();
        mv.setViewName("welcome");
        return mv;
    }
}
